<template>
	<view>
		<view class="orderPart">
			<view class="order" v-for="order in orderList">
				<view class="orderTop">
					<view class="orderNum">订单号：{{order.orderNum}}</view>
					<view class="orderStatus">{{changeStatus(order.orderStatus)}}</view>
				</view>
				<view class="orderBottom">
					<view class="orderDetail">
						<view class="leftImg">
							<image class="img" :src="order.imgSrc"></image>
							<button @click="orderComplete(order.orderNum)" v-if="order.orderStatus==5" class="mini-btn"
								type="primary" size="mini">确认收货</button>
						</view>
						<view class="rightInfo">
							<view>商品：{{order.itemName}}</view>
							<view>下单时间：{{order.buyTime}}</view>
							<view class="">支付方式：{{changePayMethod(order.payMethod)}}</view>
							<view class="">实付款：{{order.payAmount}}</view>
							<view class="commentBtn" v-if="order.orderStatus==3">
								<uni-icons @click="goComment(order.itemId)" class="icon" type="chat" size="30"
									style="font-size: 35rpx;">评价</uni-icons>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		onLoad() {
			this.selCurrentUserOrder();
		},
		data() {
			return {
				orderList: [],
				order: {}
			};
		},
		methods: {
			selCurrentUserOrder() {
				let jwt = uni.getStorageSync('authority');
				uni.request({
					url: "api/appuser/selCurrentUserOrder",
					header: {
						"authority": jwt
					},
					method: 'GET',
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							this.orderList = res.data.data;
						}
					}
				})
			},
			orderComplete(orderNum) {
				console.log(orderNum);
				this.order.orderNum = orderNum;
				let jwt = uni.getStorageSync('authority');
				uni.request({
					url: "api/appuser/orderComplete",
					method: 'POST',
					header: {
						"authority": jwt
					},
					data: this.order,
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							this.selCurrentUserOrder();
							uni.showToast({
								title: "签收成功！",
								icon: 'success'
							})
						}
					}
				})
			},
			goComment(itemId) {
				console.log(itemId);
				uni.navigateTo({
					url: "/pages/commentPage/commentPage?itemId=" + itemId
				});
			},
			changeStatus(val) {
				if (val == 1) {
					return '待付款';
				}
				if (val == 2) {
					return '已付款:  订单进行中';
				}
				if (val == 3) {
					return '已收货';
				}
				if (val == 4) {
					return '已取消';
				}
				if (val == 5) {
					return '已完成';
				}
			},
			changePayMethod(val) {
				if (val == 1) {
					return '支付宝';
				} else if (val == 2) {
					return '微信'
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f4f4f6;
	}

	.orderPart {
		width: 750rpx;
		height: 1400rpx;
		margin-top: 20rpx;

		.order {
			width: 750rpx;
			height: 300rpx;
			border-radius: 20rpx;
			margin-bottom: 25rpx;
			background: #fff;
			padding: 7rpx;
			box-sizing: border-box;
			// background-color: gray;

			.orderTop {
				width: 750rpx;
				height: 70rpx;
				border-bottom: 1px solid black;

				.orderNum {
					float: left;
					line-height: 70rpx;
					font-size: 20rpx;
				}

				.orderStatus {
					float: right;
					line-height: 70rpx;
					margin-right: 20rpx;
				}
			}

			.orderBottom {
				width: 750rpx;
				height: 200rpx;
				// background-color: green;

				.orderDetail {
					width: 100%;
					height: 100%;

					.leftImg {
						float: left;

						.img {
							width: 170rpx;
							height: 160rpx;
							display: block;
							margin-bottom: 10rpx;
						}
					}

					.rightInfo {
						float: left;

						.commentBtn {
							float: right;
							margin-left: 420rpx;
						}
					}
				}
			}

		}
	}
</style>